package com.liuyk.commonlib.web;

import java.util.HashMap;
import java.util.Map;

/**
 * 解析url参数文
 * <p>
 * Created by liuyakui on 2020/7/7
 */
public class UrlParamsParse {

    public static Map<String, String> parseUrl(String url) {
        //http://api.com?aaa=111&bbb=222&ccc=333
        if (url == null || !url.contains("?")) {
            return null;
        }
        int i = url.indexOf("?");
        String tempUrl = url.substring(i + 1);
        Map<String, String> params = new HashMap<>();
        String[] split = tempUrl.split("&");
        for (String s : split) {
            String[] temp = s.split("=");
            if (temp.length > 1) {
                params.put(temp[0], temp[1]);
            }
        }
        return params;
    }
}
